/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package grex.genes;

import grex.PredictionContainer;

import java.text.NumberFormat;

/**
 *
 * @author rik
 */
public class KnnAttWeights  extends Gene {
    private double[] attributeWeights=null;
    private static final int NROFCILDREN = 0;
    private boolean used=true;
    private double[] support;
    public KnnAttWeights() {
        super(NROFCILDREN);
    }
    
    public void initAttributesWeights() {
        attributeWeights = new double[ops.getNR_OF_INPUT_COLUMNS()];
        if (ops.rnd.nextDouble() > 0.9) {
            used = false;
            for (int i = 0; i < getAttributeWeights().length; i++)               
               attributeWeights[i] = 1;
        } else {
            for (int i = 0; i < getAttributeWeights().length; i++) {
                if (ops.isKNN_ATTRIBUTES_SELECTION()) {
                    attributeWeights[i] = Math.floor(ops.rnd.nextDouble() * 1.99);
                } else {
                    attributeWeights[i] = ops.rnd.nextDouble();
                }
            }
        }
    }
     
     

    @Override
    public void execute(Gene parent, PredictionContainer data, int mode) throws GeneException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public Object clone() {
        KnnAttWeights kaw = new KnnAttWeights();
        kaw.attributeWeights=getAttributeWeights();
        kaw.setOptions(ops);
        kaw.setEnvironment(environment);        
        kaw.setParent(parent);
        kaw.used=used;
        return kaw;
    }

    @Override
    public String toString() {
         String s ="";
         if((ops.isKNN_WEIGHTED_ATTRIBUTES()||ops.isKNN_ATTRIBUTES_SELECTION())&&used){
           NumberFormat nf = NumberFormat.getInstance();
           nf.setMaximumFractionDigits(1);
           s+=" [ ";
           for (int i = 0; i < getAttributeWeights().length; i++) {
               s+= nf.format(getAttributeWeights()[i])+" ";

           }
           s+="]";
         }else{
             s="[not used]";
         }
       return s;
    }

    public double[] getAttributeWeights() {
        if(attributeWeights==null)
            initAttributesWeights();
        return attributeWeights;
    }

    public double getProb() {
        return 0;
    }

    public double getLowProb() {
       return 0;
    }

    public int getCount() {
       return 1;
    }
}
